<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler' :tableObj='$refs.table'>
      <f-search-form-item label='单据日期' type='range' name='beginDate' />
      <f-search-form-item label='部门' ref='dept' name='deptId' type='select' :data='api.dept.list' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='订单编号' name='orderNo' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='orderNo' :showSetting='true' setting-key='remoter2'
             :tableColumns='columns' :multiple='true' :scroll='scroll' :operator='operator' :params='queryParam'
             :api='api.hyOrderOut'>
      <span slot='saleType' slot-scope='text'>
        <a-tag color='#2db7f5' v-if='text=="CKA"'>销售订单</a-tag>
        <a-tag v-if='text=="CHB"'>销售计划单</a-tag>
        <a-tag v-if='text=="CHC"'>销售退回通知单</a-tag>
        <a-tag v-if='text=="CHD"'>调出订单</a-tag>
        <a-tag v-if='text=="CHE"'>调出计划单</a-tag>
        <a-tag v-if='text=="CHF"'>调出退回通知单</a-tag>
        <a-tag v-if='text=="CHG"'>报损审批单</a-tag>
        <a-tag v-if='text=="CHH"'>销售退回收货单</a-tag>
        <a-tag v-if='text=="CHI"'>调出退回收货单</a-tag>
        <a-tag v-if='text=="CHJ"'>销售批号更正单</a-tag>
        <a-tag v-if='text=="CHK"'>调出批号更正单</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
        <template>
          <a href='javascript:;' @click='initOrder(record)' v-if='record.saleType=="CKA"'>同步订单</a>
          <a-divider type='vertical' />
          <a @click='$refs.orderInfoDrawer.showDrawer(record)'>详情</a>
        </template>
      </span>
    </f-table>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>

<script>
import api from "./js/api"
import OrderInfoDrawer from "./order_info2_drawer"

export default {
  name: "HyOrderList",
  components: {
    OrderInfoDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "批量同步",
      that: this,
      handler: (table, that) => {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          this.http.confirm(this, {
            content: "确认同步订单到结算系统吗?",
            url: api.hyOrder.syncOrder,
            data: {
              orderNo: selectIds.join(",")
            },
            success: (me, data) => {
              this.$refs["table"].refresh(false)
            }
          })
        } else {
          that.$message.error("请选择订单")
        }
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        companyId: ""
      },
      superAdmin: this.superAdmin,
      processImageVisible: false,
      scroll: { x: true },
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          dataIndex: "rowIndex",
          customRender: function(text, r, index) {
            return (text !== "合计") ? (parseInt(index) + 1) : text
          }
        },
        {
          title: "操作",
          align: "center",
          width: "120px",
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单据日期",
          align: "center",
          width: "150px",
          dataIndex: "orderDate"
        },
        {
          title: "订单编号",
          align: "center",
          width: "140px",
          ellipsis: true,
          dataIndex: "orderNo"
        },
        {
          title: "单位名称",
          align: "center",
          width: "140px",
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "部门名称",
          align: "center",
          width: "90px",
          dataIndex: "deptName"
        },
        {
          title: "出库方式",
          align: "center",
          width: "140px",
          dataIndex: "saleType",
          scopedSlots: { customRender: "saleType" }
        },
        {
          title: "开票员",
          align: "center",
          width: "130px",
          dataIndex: "userName"
        },
        {
          title: "单位编码",
          align: "center",
          width: "180px",
          dataIndex: "companyCode"
        },
        {
          title: "业务员",
          align: "center",
          ellipsis: true,
          width: "180px",
          dataIndex: "saleManName"
        },
        {
          title: "数量",
          align: "center",
          width: "140px",
          dataIndex: "saleNum"
        },
        {
          title: "销售金额",
          align: "center",
          width: "140px",
          dataIndex: "saleAmount"
        }
      ],
      operator: operator
    }
  },
  methods: {
    initOrder(record) {
      this.http.confirm(this, {
        content: "确认同步订单到结算系统吗?",
        url: api.hyOrder.syncOrder,
        data: {
          orderNo: record.orderNo
        },
        success: (me, data) => {
          this.$refs["table"].refresh(false)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>